package api

import (
	"github.com/gin-gonic/gin"
	"github.com/share309/gojwt"
	"new_house/api/handler"
	"new_house/api/middleware"
	"new_house/consts"
)

func LoadRoutes(r *gin.Engine) {
	r.GET("/ping", handler.Ping)
	r.Use(middleware.Cors())
	api := r.Group("/api")
	{
		user := api.Group("/user")
		{
			user.POST("/register", handler.Register)
			user.POST("/login", handler.Login)
			user.Use(gojwt.JWTAuth(consts.JWT_KEY))
			user.POST("/refreshToken", handler.RefreshToken)
		}
		house := api.Group("/house")
		{
			house.Use(gojwt.JWTAuth(consts.JWT_KEY))
			house.POST("/add", handler.AddHouse)
			house.GET("/list", handler.GetHousePageList)
			house.GET("/detail", handler.GetHouseDetail)
			house.POST("/upload", handler.Upload)
			house.POST("/uploadVideoUrl", handler.UploadVideoUrl)
			house.POST("/updateHousePrice", handler.UpdateHousePrice)

		}
		appointment := api.Group("/appointment")
		{
			appointment.Use(gojwt.JWTAuth(consts.JWT_KEY))
			appointment.POST("/add", handler.AddAppointment)
			appointment.POST("/remove", handler.RemoveAppointment)
		}
		order := api.Group("/order")
		{
			order.Use(gojwt.JWTAuth(consts.JWT_KEY))
			order.POST("/add", handler.AddOrder)
			order.POST("/uploadOrderUrl", handler.UploadOrderUrl)
			order.GET("/list", handler.GetOrderPageList)
			order.POST("/update", handler.UpdateOrderStatus)
		}
		chat := api.Group("/chat")
		{
			chat.Use(gojwt.JWTAuth(consts.JWT_KEY))
			chat.GET("/ws", handler.Chat)
		}
	}
}
